//
// Created by 11510 on 2024/6/11.
//

#ifndef LOG4SINGLE_MYLOGGER_H
#define LOG4SINGLE_MYLOGGER_H
#include <string>
#include <log4cpp/Category.hh>

using std::string;

class MyLogger {
public:
    static MyLogger* getInstance();
    static void destroy();

    /**
     * 设置为友元函数，可以访问私有成员
     * @param msg
     */
    friend void LogInfo(string &msg);
    friend void LogError(string &msg);
    friend void LogWarn(string &msg);
    friend void LogDebug(string &msg);

private:
    MyLogger();
    ~MyLogger();

    void warn(string &msg);
    void error(string &msg);
    void debug(string &msg);
    void info(string &msg);

    MyLogger(MyLogger &rhs) = delete;
    MyLogger &operator=(const MyLogger &rhs) = delete;

    static MyLogger *_myLogger;
    log4cpp::Category& _root;
    log4cpp::Category& _sub1;
    log4cpp::Category& _sub2;
};

void LogInfo(string &msg);
void LogError(string &msg);
void LogWarn(string &msg);
void LogDebug(string &msg);



// test demo
void log4test();
#endif //LOG4SINGLE_MYLOGGER_H
